Skip to content

Add note about not needing jsx-no-undef with TS / typescript-eslint #3941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

karlhorky
Copy link
Contributor

@karlhorky karlhorky commented Aug 3, 2025

Hi @ljharb, hope everything is going well! 👋

Quick PR to add an additional 2 cases of when to not use react/jsx-no-undef

  1. when using TypeScript, since it has better checks than ESLint no-undef rules

  2. the @typescript-eslint/parser parser allows for usage of ESLint's built-in no-undef without react/jsx-no-undef:

    Screenshot 2025-08-03 at 13 56 31

    This applies to:

    1. .tsx files (as demonstrated in the typescript-eslint Playground link)
    2. .jsx or .js files - also without "allowJs": true or "checkJs": true in tsconfig.json.

@karlhorky karlhorky changed the title Add note about not needing jsx-no-undef with typescript-eslint Add note about not needing jsx-no-undef with TS / typescript-eslint Aug 9, 2025
It's recommended to avoid this rule if your project:

1. does not use JSX
2. uses TypeScript, which [automatically enables better checks than ESLint `no-undef` rules](https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item 2 and 3 are basically the same - it would be a very bad idea to turn off this rule and NOT enable the typescript-eslint rule.

Copy link
Contributor Author

@karlhorky karlhorky Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, well following the advice from the typescript-eslint docs, actually the no-undef rule should be disabled in TypeScript files

So option 3 is for files where TS type checking is disabled, eg. JS files in a typescript-eslint project

If that doesn't make sense, I can try re-explaining

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, hmm, ok - which version of TS enabled these better checks? (because TS definitely did not used to do a better job than this rule)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'm thinking that this was like this from pretty early on... can't remember a time when TS didn't give me errors for undefined JSX element identifiers 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the TS playground goes back to version 3.3.3333, and it seems like it's present there:

Screenshot 2025-08-13 at 19 38 55

https://www.typescriptlang.org/play/?ts=3.3.3#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoSygHgAkkAbBiOAOxRCQF4AiAKQgALVjzgB6AHykgA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants